package cn.biplam.front.htmlscript.script;

import cn.biplam.common.tools.TOOLS;
import cn.biplam.common.wrapper.ErrorMessage;

/**
 * 新树的刷新脚本
 * @author WangSong 2009-10-22上午10:14:45
 * @version 1.0
 */
public class ScriptTreeNew {
	
	/**
	 * 树添加的刷新脚本(部分刷新)
	 * @param nodeCid 添加节点时右键点击节点的容器id(在右键弹出页面可接收：params.getByKey(TreeParam.NODE_CONTARINER_ID))
	 * @param treeActionId 树vc的行为id
	 * @param nodeId 添加的节点id
	 * @return 树添加的刷新脚本
	 */
	public static String getRefreshAdd(String nodeCid,String treeActionId,String nodeId){
		StringBuilder sb = new StringBuilder();
		sb.append("addRf('");
		sb.append(nodeCid);
		sb.append("','");
		sb.append(treeActionId);
		sb.append("','");
		sb.append(nodeId);
		sb.append("');");
		return sb.toString();
	}
	
	/**
	 * 树修改的刷新脚本(部分刷新)
	 * @param nodeCid 添加节点时右键点击节点的容器id(在右键弹出页面可接收：params.getByKey(TreeParam.NODE_CONTARINER_ID))
	 * @param treeActionId 树vc的行为id
	 * @return 树添加的刷新脚本
	 */
	public static String getRefreshModify(String nodeCid,String treeActionId){
		StringBuilder sb = new StringBuilder();
		sb.append("modifyRf('");
		sb.append(nodeCid);
		sb.append("','");
		sb.append(treeActionId);
		sb.append("');");
		return sb.toString();
	}
	
	/**
	 * 树删除的刷新脚本(部分刷新)
	 * @param nodeCid 添加节点时右键点击节点的容器id(在右键弹出页面可接收：params.getByKey(TreeParam.NODE_CONTARINER_ID))
	 * @param treeActionId 树vc的行为id
	 * @return 树添加的刷新脚本
	 */
	public static String getRefreshDelete(String nodeCid,String treeActionId){
		StringBuilder sb = new StringBuilder();
		sb.append("deleteRf('");
		sb.append(nodeCid);
		sb.append("','");
		sb.append(treeActionId);
		sb.append("');");
		return sb.toString();
	}
	
	/**
	 * 树的刷新脚本(整体刷新:从根开始刷新,并展开需要显示的节点)
	 * @param pcid 调用树的Vc的容器id (params.getByKey("TreeParam.TREE_PCID"))
	 * @param actionId 生成树的vc的行为id (params.getByKey("TreeParam.TREE_AID"))
	 * @param treeIndex 树的编号 (params.getByKey("TreeParam.TREE_INDEX"))
	 * @param extendNodeId 需要展开的节点id
	 * @param extendClick 是否点击当前展开的节点
	 * @return 数的刷新脚本(单棵树)
	 * @throws ErrorMessage 
	 */
	public static String getRefresh(String pcid,
									String actionId,
									String treeIndex,
									String extendNodeId,
									boolean extendClick) throws ErrorMessage{
		if(TOOLS.StringIsEmpty(pcid)){
			throw new ErrorMessage("ScriptTreeNew.getRefresh() Error, pcid is null");
		}
		if(TOOLS.StringIsEmpty(actionId)){
			throw new ErrorMessage("ScriptTreeNew.getRefresh() Error, actionId is null");
		}
		if(TOOLS.StringIsEmpty(treeIndex)){
			throw new ErrorMessage("ScriptTreeNew.getRefresh() Error, treeIndex is null");
		}
		StringBuilder sb = new StringBuilder();
		String click = "0";
		if(extendClick){
			click = "1";
		}
		
		sb.append("treeWholeRefreshNew(");
		sb.append("'"+TOOLS.stringClip(pcid, 4)+"',");
		sb.append("'"+actionId+"',");
		sb.append("'"+extendNodeId+"',");
		sb.append("'"+click+"',");
		sb.append("'"+treeIndex+"'");
		sb.append(");");
		
		return sb.toString();
	}
}
